<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请开店列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="case-form">
                <input name="reviewStatus" type="hidden" value="1">
                <div class="select-list">
                    <ul>
                        <li>
                            小程序店铺名：<input type="text" name="shopName"/>
                        </li>
                        <li>
                            小程序店铺昵称：<input type="text" name="shopCode"/>
                        </li>
                        <li>
                            申请人名称：<input type="text" name="applicantName"/>
                        </li>
                        <li>
                            申请人手机：<input type="text" name="applicantPhone"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <!--<div class="btn-group-sm" id="toolbar" role="group">-->
            <!--<a class="btn btn-success" onclick="productCategoryEdit(0)" shiro:hasPermission="back:productCategory:shopEdit">-->
                <!--设置店铺商品分类-->
            <!--</a>-->
        <!--</div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('back:shopApply:edit')}]];
    var changeBalanceFlag = [[${@permission.hasPermi('back:shopBalance:change')}]];
    var editProductCategoryFlag = [[${@permission.hasPermi('back:productCategory:shopEdit')}]];
    const openStatusDict = [[${@dict.getType('open_status')}]]
    var prefix = ctx + "back/shop";

    /* 改变状态 */
    function changeStatus(id, isEnable) {
        isEnable = Math.abs(parseInt(isEnable) - 1);
        $.operate.post(prefix + "/edit", {id: id, isEnable: isEnable}, function () {
            $.table.refresh();
        })
    }

    $(function () {
        var options = {
            url: prefix + "/searchList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            modalName: "申请开店",
            columns: [
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'shopName',
                    title: '小程序店铺名',
                    sortable:true
                },
                {
                    field: 'shopCode',
                    title: '小程序店铺昵称',
                    sortable:true
                },
                {
                    field: 'parentShopName',
                    title: '上级小程序店铺名',
                    sortable:true,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<br/><a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="changeParent(\'' + row.id + '\')">更换</i></a>');
                        return $.common.isEmpty(value)?"":value+actions.join('');
                    }
                },
                {
                    field: 'applicantName',
                    title: '申请人名称',
                    sortable:true
                },
                {
                    field: 'applicantPhone',
                    title: '申请人手机',
                    sortable:true
                },
                {
                    field: 'balance',
                    title: '店铺余额',
                    sortable:true
                },
                {
                    field: 'isEnable',
                    title: '店铺状态',
                    sortable:true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(openStatusDict, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit">编辑</i></a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + changeBalanceFlag + '" href="#" onclick="changeBalance(\'' + row.id + '\')"><i class="fa fa-money">余额调整</i></a>');
                        actions.push('<a class="btn btn-success btn-xs ' + editProductCategoryFlag + '" href="#" onclick="productCategoryEdit(\'' + row.id + '\')">设置商品分类</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function changeBalance(shopId) {
        var url = ctx + 'back/shopBalance/change/' + shopId;
        $.modal.open("余额调整", url);
    }

    function changeParent(shopId) {
        var url = ctx + 'back/shop/changeParent/' + shopId;
        $.modal.open("上级店铺变更", url);
    }

    /* 设置店铺商品分类 */
    function productCategoryEdit(shopId) {
        var url = ctx + 'back/productCategory/shopEdit/'+shopId;
        $.modal.open("设置店铺分类", url);
    }
</script>
</body>
</html>